#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QAbstractItemModel>
#include <QStyledItemDelegate>
#include <QListView>

namespace Ui {
class MainWindow;
}

class ItemDelegate : public QStyledItemDelegate
{
public:
    ItemDelegate(QObject *parent = nullptr);

    virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
};

class ListModel : public QAbstractItemModel
{

    Q_OBJECT
public:
    explicit ListModel();
    ~ListModel();

    void addRow(Qt::GlobalColor color);
    void deleteRow(int index);
    virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
    virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
    virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
    virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
    virtual QModelIndex parent(const QModelIndex &index) const;

signals:

private:
    QList<Qt::GlobalColor> m_lstColor;
};

class ListView : public QListView
{
    Q_OBJECT
public:
    explicit ListView(QWidget *parent = nullptr);
    ~ListView();

};

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    friend class autoTest;
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void on_btnDelete_clicked();
    void on_btnAdd_clicked();
    void viewClicked(const QModelIndex &index);

private:
    Ui::MainWindow *ui;
    ListModel *m_Model;
    ItemDelegate *m_Delegate;
    ListView *m_ListView;
};

#endif // MAINWINDOW_H
